using System;

namespace Copperline.Escriba
{
	/// <summary>
	/// Defines the condition for sinking a log entry.
	/// </summary>
	/// <remarks>Loggers determine whether to sink a log event by comparing the
	/// severity of the event with the configured minimum severity. The comparison
	/// is controlled by the setting of the trigger: either the severities must
	/// <c>match</c>, or the logger's configured severity is treated as a
	/// <c>threshold</c> that the event's severity must equal or exceed.
	/// <seealso cref="ESeverity"/></remarks>
	public enum ETrigger 
	{
		/// <summary>
		/// The logger's configured severity is treated as a threshold.
		/// Log events must have a severity at least equal to the configured severity
		/// before they will be logged.
		/// </summary>
		threshold = 0,
		/// <summary>
		/// The logger's configured severity is treating as a matching condition.
		/// Log events must have a severity equal to the configured severity
		/// before they will be logged.
		/// </summary>
		match = 1
	};

	/// <summary>
	/// Defines a common base class for filters.
	/// </summary>
	public abstract class FilterBase : IFilter
	{
		private ETrigger trigger;
		/// <summary>
		/// Sets or gets the trigger condition that LogEntry instances must satisfy
		/// </summary>
		public ETrigger Trigger
		{
			get { return trigger; }
			set { trigger = value; }
		}

		private ESeverity severity;
		/// <summary>
		/// Sets or gets the severity condition that LogEntry instances must satisfy
		/// </summary>
		public ESeverity Severity
		{
			get { return severity; }
			set { severity = value; }
		}

		/// <summary>
		/// Returns <c>true</c> if the severity of the log entry matches or exceeds the severity of the logger
		/// </summary>
		/// <param name="severityOfEntry">the severity of the log entry</param>
		/// <returns><c>true</c> if the preconfigured trigger condition is satisfiled</returns>
		public abstract bool HasRequiredSeverity(ESeverity severityOfEntry);
	}
}
